package top.heue.utils.log.handler

import org.json.JSONArray
import org.json.JSONObject
import top.heue.utils.log.base.BaseHandler

class JSONHandler : BaseHandler<Any>() {
    override val priority: Int = 998
    private val anyHandler by lazy { AnyHandler() }
    override fun canHandle(any: Any?): Boolean =
        any is JSONObject || any is JSONArray

    override fun handle(any: Any): String {
        return when (any) {
            is JSONObject -> any.toString(4)
            is JSONArray -> any.toString(4)
            else -> anyHandler.handle(any)
        }
    }
}
